Developer Documentation

QuickTime 4 API Documentation

QuickTime 4 Reference

| Previous | Chapter Contents | Chapter Top | Next |

Working with Alpha Channels

QuickTime has always supported compressing and storing images with an alpha channel. In QuickTime 2.5, the Image Compression Manager was updated to support using the alpha channel when displaying images. Alpha channels are supported only for 32-bit images. The high byte of each pixel contains the alpha channel. The alpha channel can be interpreted in one of three ways:

QuickTime uses the alpha channel to define how an image is to be combined with the image that is already present at the location to which it will be drawn. This is similar to how QuickDraw's blend mode works. To combine an image containing an alpha channel with another image, you specify how the alpha channel should be interpreted by specifying one of the new alpha channel graphics modes defined by QuickTime.

Straight alpha means that the color components of each pixel should be combined with the corresponding background pixel based on the value contained in the alpha channel. For example, if the alpha value is 0, only the background pixel will appear. If the alpha value is 255, only the foreground pixel will appear. If the alpha value is 127, then (127/255) of the foreground pixel will be blended with (128/255) of the background pixel to create the resulting pixel, and so on.

Pre-multiplied with white means that the color components of each pixel have already been blended with a white pixel, based on their alpha channel value. Effectively, this means that the image has already been combined with a white background. To combine the image with a different background color, QuickTime must first remove the white from each pixel and then blend the image with the actual background pixels. Images are often pre-multipled with white as this reduces the appearance of jagged edges around objects.

Pre-multipled with black is the same as pre-multipled with white, except the background color that the image has been blended with is black instead of white.

Note
Although you pass these new alpha channel graphics modes to QuickTime in the same way as you would traditional QuickDraw transfer modes, these modes are not supported by QuickDraw and will cause unpredictable results if passed to QuickDraw routines.

The Image Compression Manager defines the following constants for specifying alpha channel graphics modes:

enum {
    graphicsModeStraightAlpha       = 256,
    graphicsModePreWhiteAlpha       = 257,
    graphicsModePreBlackAlpha       = 258
    graphicsModeStraightAlphaBlend  = 260
};

The graphicsModeStraightAlpha , graphicsModePreWhiteAlpha , and graphicsModePreBlackAlpha graphics modes cause QuickTime to draw the image interpreting the alpha channel as specified. The graphics mode graphicsModeStraightAlphaBlend causes QuickTime to interpret the alpha channel as a straight alpha channel, but when it draws, combines the pixels together and applies the opColor supplied with the graphics mode to the alpha channel. This provides an easy way to combine images using both an alpha channel and a blend level. This can be useful when compositing 3D rendered images over video.

To draw a compressed image containing an alpha channel, that image must be compressed using an image-compression format that is capable of storing the alpha channel information. The Animation, Planar RGB and None compressors store alpha channel data in the "Millions of Colors +" (32-bit) mode.

You use the MediaSetGraphicsMode function to set a movie track to use an alpha channel graphics mode. You use the SetDSequenceTransferMode function to set an image sequence to use an alpha channel graphics mode.


© 1999 Apple Computer, Inc.

| Previous | Chapter Contents | Chapter Top | Next |